Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bake(dev): plugins in dev server, with other fixes #15467

Merged
merged 11 commits into from
Nov 30, 2024
Merged

Conversation

paperdave
Copy link
Member

  • load plugins in dev mode
  • pass resolveDir to onResolve plugins
  • onLoad plugin with css loader now works
  • hmr instrumentation for export { x } from 'y';
  • fixed export { x as y }
  • throw SyntaxError The requested module '${id}' does not provide an export named '${key}'
  • stub import.meta.hot, implement import.meta.hot.dispose

example project: https://github.com/paperdave/bake-svelte-plugin-example

@robobun
Copy link

robobun commented Nov 28, 2024

@Jarred-Sumner, your commit 8fa6db3 has 14 failures in #7119:

  • test/js/bun/http/bun-serve-static.test.ts - timeout on 🐧 3.20 x64
  • test/integration/next-pages/test/dev-server.test.ts - 1 failing on 🐧 3.20 x64-baseline
  • test/integration/next-pages/test/dev-server.test.ts - 1 failing on 🐧 3.20 x64
  • test/cli/hot/hot.test.ts - timeout on 🐧 22.04 x64-baseline
  • test/cli/hot/hot.test.ts - timeout on 🐧 3.20 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 20.04 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 3.20 aarch64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 22.04 x64
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 22.04 x64-baseline
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 3.20 x64-baseline
  • test/js/node/test/parallel/fs-watch-recursive-linux-parallel-remove.test.js - 1 failing on 🐧 3.20 x64
  • test/v8/v8.test.ts - 22 failing on 🐧 3.20 aarch64
  • test/v8/v8.test.ts - 22 failing on 🐧 3.20 x64-baseline
  • test/v8/v8.test.ts - 22 failing on 🐧 3.20 x64
  • test/js/node/child_process/child_process.test.ts - 1 failing on 🐧 3.20 aarch64
  • test/js/node/child_process/child_process.test.ts - 1 failing on 🐧 3.20 x64-baseline
  • test/js/node/child_process/child_process.test.ts - 1 failing on 🐧 3.20 x64
  • test/regression/issue/09041.test.ts - 1 failing on 🐧 22.04 x64
  • test/regression/issue/09041.test.ts - 1 failing on 🐧 20.04 x64-baseline
  • test/js/bun/http/serve.test.ts - SIGTRAP on 🐧 3.20 aarch64
  • test/js/bun/http/serve.test.ts - SIGILL on 🐧 3.20 x64-baseline
  • test/js/bun/http/serve.test.ts - SIGILL on 🐧 3.20 x64
  • test/js/node/test/parallel/worker-nested-uncaught.test.js - segmentation fault on 🐧 3.20 aarch64
  • test/js/web/timers/setTimeout.test.js - 1 failing on 🐧 22.04 aarch64
  • test/cli/install/bun-link.test.ts - 1 failing on 🐧 22.04 x64
  • test/integration/next-pages/test/next-build.test.ts - 1 failing on 🍎 14 x64
  • test/integration/next-pages/test/next-build.test.ts - 1 failing on 🐧 22.04 aarch64
  • test/js/node/dns/node-dns.test.js - 1 failing on 🪟 2019 x64
  • test/js/web/timers/setInterval.test.js - 1 failing on 🪟 2019 x64
  • @@ -2034,15 +2045,16 @@ pub fn IncrementalGraph(side: bake.Side) type {
    const dev = g.owner();
    dev.graph_safety_lock.assertLocked();

    const abs_path = ctx.sources[index.get()].path.text;
    const path = ctx.sources[index.get()].path;
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Is this copy intentional? Can it be a pointer instead? Path is not a small struct

    Suggested change
    const path = ctx.sources[index.get()].path;
    const path = &ctx.sources[index.get()].path;

    promise.setHandled(global.vm());
    // TODO: remove this call, replace with a promise list that must
    // be resolved before the first bundle task can begin.
    global.bunVM().waitForPromise(promise);
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    sad

    @@ -521,6 +583,10 @@ pub const Framework = struct {
    if (renderer == .server and framework.server_components != null) {
    try out.options.conditions.appendSlice(&.{"react-server"});
    }
    if (mode == .development) {
    // Support `esm-env` package using this condition.
    try out.options.conditions.appendSlice(&.{"development"});
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    i've never heard of this

    @@ -76,7 +91,79 @@ if (side === "server") {
    }

    function initImportMeta(m: HotModule): ImportMeta {
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    This is client-side, for browsers I assume?

    if (source_code_value.isEmptyOrUndefinedOrNull() or loader_as_int.isEmptyOrUndefinedOrNull()) {
    this.value = .{ .no_match = {} };

    if (this.was_file) {
    // Faster path: skip the extra threadpool dispatch
    completion.bundler.graph.pool.pool.schedule(bun.ThreadPool.Batch.from(&this.parse_task.task));
    this.bv2.graph.pool.pool.schedule(bun.ThreadPool.Batch.from(&this.parse_task.task));
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    bv2 implies the existence of bv3 and bv1

    is there a better name?

    @@ -1783,13 +1835,15 @@ pub const BundleV2 = struct {
    this.graph.heap.gc(true);
    }
    }
    var log = &load.completion.?.log;
    const log = this.bundler.log;
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Why was this changed? This will crash if the bundler thread writes to logger.Log at the same time as the main thread. When using Bun.build that can happen.

    @@ -1846,7 +1922,7 @@ pub const BundleV2 = struct {
    this.graph.heap.gc(true);
    }
    }
    var log = &resolve.completion.?.log;
    const log = this.bundler.log;
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Ditto. We shouldn't change this unless we're confident there's no thread-safety issue.

    if (!record.source_index.isValid()) continue;
    if (loaders[record.source_index.get()] != .css) continue;
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    This is an extra pointer lookup, which slightly slows things down. Was the import_record.tag inaccurate?

    @@ -2595,7 +2666,7 @@ pub const BundleV2 = struct {
    import_record.path.pretty = rel;
    import_record.path = this.pathWithPrettyInitialized(path.*, target) catch bun.outOfMemory();
    if (entry.kind == .css) {
    import_record.tag = .css;
    import_record.path.is_disabled = true;
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Can you leave a comment explaining this?

    temp,
    visits,
    o,
    record.source_index,
    record.tag == .css,
    loaders[record.source_index.get()] == .css,
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    If we can continue to use record.tag that's one less pointer lookup


    // add a marker for the client runtime to tell that this is an ES module
    if (ast.exports_kind == .esm) {
    try stmts.inside_wrapper_prefix.append(Stmt.alloc(S.SExpr, .{
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    This would ideally use the lazy export AST and then it can choose whichever output format is best.

    @@ -334,12 +335,12 @@ export function runOnResolvePlugins(this: BundlerPlugin, specifier, inputNamespa
    }
    }

    export function runOnLoadPlugins(this: BundlerPlugin, internalID, path, namespace, defaultLoaderId) {
    export function runOnLoadPlugins(this: BundlerPlugin, internalID, path, namespace, defaultLoaderId, isServerSide: boolean) {
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Maybe isServerSide could be an enum to clarify whether it means:

    • RSC
    • SSR
    • !browser

    // This is a re-export and the symbols created here are used to reference
    for (data.items) |*item| {
    const _name = p.loadNameFromRef(item.name.ref.?);
    const ref = try p.newSymbol(.other, _name);
    const ref = try p.newSymbol(.import, _name);
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    ooh i wonder what bugs this causes

    column: i32,
    /// Number of bytes this location should highlight.
    /// 0 to just point at a single character
    length: usize = 0,
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    yeah this struct wasn't thoughtfully created, it was copypasta from esbuild

    @@ -607,6 +607,9 @@ pub const ParseResult = union(enum) {
    .location = Logger.Location{
    .file = path,
    .offset = this.loc.toUsize(),
    // TODO: populate correct line and column information
    .line = -1,
    Copy link
    Collaborator

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    We need to port the LineColumnTracker abstraction esbuild has

    Copy link
    Collaborator

    @Jarred-Sumner Jarred-Sumner left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Some comments. Only blocking comment is the change to reference bundler.log, as I worry it will cause crashes in Bun.build.

    @Jarred-Sumner Jarred-Sumner marked this pull request as ready for review November 30, 2024 02:26
    @Jarred-Sumner
    Copy link
    Collaborator

    I’m going to merge this to unblock further progress, but please take a look at the comments when you get a chance.

    @Jarred-Sumner Jarred-Sumner merged commit 8aa451c into main Nov 30, 2024
    66 of 67 checks passed
    @Jarred-Sumner Jarred-Sumner deleted the dave/dev-plugins branch November 30, 2024 03:07
    snoglobe pushed a commit that referenced this pull request Dec 4, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants